package values.skill
{
	import core.manager.battle.BattleCountManager;
	import core.manager.battle.BattleEffectManager;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import values.avatar.AvatarCampTypeKey;
	import values.avatar.IAvatarValue;
	
	public class AdditionalEffectValue extends EventDispatcher implements IAdditionalEffectValue
	{
		
		public function AdditionalEffectValue()
		{
			super();
		}
		
		protected var _owner:IAvatarValue;
		
		protected var _hitter:IAvatarValue;
		
		protected var _skillValue:SkillValue;
		
		protected var _baseDamageNum:Number;
		
		protected var _kill:Boolean;
		
		public function init(owner:IAvatarValue, hitter:IAvatarValue, skillValue:SkillValue, baseDamageNum:Number=0 , kill:Boolean = false):void
		{
			_owner = owner;
			
			_hitter = hitter;
			
			_skillValue = skillValue;
			
			_baseDamageNum = baseDamageNum;
			
			_kill = kill;
			
			if(_skillValue.template.additional.target == AvatarCampTypeKey.ME)
			{
				_hitter = _owner;
			}
		}
		
		public function effect():void
		{
			var tempateV:AdditionalEffectTemplateValue = _skillValue.template.additional;
			//////////////////////////几率没达到///////////////////////////////
			if(!BattleCountManager.countRandom(_skillValue.getLevelValueByTag(tempateV.basePossiblity))) return;
			/////////////////////////被抵抗了/////////////////////////////////
			if(tempateV.canResist && !_skillValue.checkSkillHasLogic(LogicEffectValue.IGNORE_RESIST) && BattleCountManager.countRandom(BattleCountManager.countResistRate(_owner , _hitter))) return;
			
			var effectObj:Object = {};
			var num:Number;
			for each(var proV:AdditionalProTemplateValue in tempateV.proDic)
			{
				if(_hitter[proV.proName] != null)
				{
					if(proV.needBaseNum)
					{
						num = _baseDamageNum * _skillValue.getLevelValueByTag(proV.baseNum) / 100;
						_hitter[proV.proName] -= num;
					}
					else
					{
						num = SkillNumTypeKey.getResult(proV.numType , _hitter[proV.proName] , _skillValue.getLevelValueByTag(proV.baseNum));
						_hitter[proV.proName] -= num;
					}
					
					BattleEffectManager.showEffectValue(_owner , _hitter , {num:num , proName:proV.proName});
				}
			}
		}
		
		public function dispose():void
		{
			_owner = null;
			_hitter = null;
			_skillValue = null;
		}
	}
}